/*
 * Copyright 2006 Abdulla G. Abdurakhmanov (abdulla.abdurakhmanov@gmail.com).
 * 
 * Licensed under the GPL, Version 2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.gnu.org/copyleft/gpl.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * With any your questions welcome to my e-mail 
 * or blog at http://abdulla-a.blogspot.com.
 */

package org.ofsm.creator;

import javax.swing.table.AbstractTableModel;

import org.jgraph.JGraph;

import org.ofsm.impl.FileFiniteStateMachineBaseModel;
import org.ofsm.impl.FileFiniteStateMachineModel;
import org.ofsm.impl.StateTransition;

public class StateDiagramItemTablePropertiesModel extends AbstractTableModel{
    private FileFiniteStateMachineModel model;
    private JGraph graph;
    private String[] columnNames = {"Attribute", "Value"};
    
    public StateDiagramItemTablePropertiesModel(FileFiniteStateMachineModel model, JGraph graph) {
        this.model = model;
        this.graph = graph;
    }
        
    public int getColumnCount() {
        return columnNames.length; 
    } 
    
    public int getRowCount() {
        if(graph.getSelectionCount() == 1) {
            Object obj = graph.getSelectionCell();
            if(obj instanceof EventGraphEdge) {
                return 2;
            }
            if(obj instanceof StateGraphCell) {
                return 2;
            }
        }    
        return 0;
    } 
    
    public Object getValueAt(int row, int col) {
        if(graph.getSelectionCount() == 1) {
            Object obj = graph.getSelectionCell();
            if(obj instanceof EventGraphEdge) {
                if(row == 1) {
                    if(col == 0) {
                        return "Event name";
                    }
                    else
                        return ((EventGraphEdge)obj).getEventInfo().getEvent().getName();
                }
                else {
                    if(col == 0) {
                        return "Event class name";
                    }
                    else
                        return ((EventGraphEdge)obj).getEventInfo().getClassName();
                }
            }
            if(obj instanceof StateGraphCell) {
                if(row == 1) {
                    if(col == 0) {
                        return "State name";
                    }
                    else
                        return ((StateGraphCell)obj).getStateInfo().getState().getName();
                }
                else {
                    if(col == 0) {
                        return "State class name";
                    }
                    else
                        return ((StateGraphCell)obj).getStateInfo().getClassName();
                }
            }
        }    
        return null;
    }
    
    public String getColumnName(int column) {
        return columnNames[column];
    }
    
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();                
    }
    
    public boolean isCellEditable(int row, int col) { 
        return false;
    }
    
    public void setValueAt(Object aValue, int row, int col) { 
    }
}
